package com.dormitory.management.system.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dormitory.management.system.entity.Health;
import com.dormitory.management.system.req.HealthPageReq;
import com.dormitory.management.system.req.HealthSaveReq;
import com.dormitory.management.system.req.HealthUpdateReq;
import com.dormitory.management.system.resp.HealthPageResp;
import com.dormitory.management.system.service.HealthService;
import com.dormitory.managemnet.util.core.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 防疫健康表 前端控制器
 * </p>
 *
 * @author
 * @since 2021-12-17
 */
@Api(tags = "疫情管理")
@RestController
@RequestMapping("/health")
public class HealthController {
    @Autowired
    HealthService healthService;

    @ApiOperation("疫情表简略信息")
    @RequestMapping(value = "getPage",method = RequestMethod.POST)
    public Result<IPage<HealthPageResp>> getPageSimple(@RequestBody HealthPageReq req){
        return Result.ok(healthService.getPage(req));
    }

    @ApiOperation("疫情表插入")
    @RequestMapping(value = "/save",method = RequestMethod.POST)
    public Result<String> save(@RequestBody HealthSaveReq req){
        if(!healthService.save(req)) {
            return Result.error("添加失败！");
        }
        return Result.success("添加成功！");
    }

    @ApiOperation("疫情表删除")
    @RequestMapping(value = "/delete/{id}",method = RequestMethod.GET)
    public Result<String> delete(
            @ApiParam(value = "疫情id",required = true)
            @PathVariable Long id){
        if(!healthService.delete(id)) {
            return Result.error("删除失败！");
        }
        return Result.success("删除成功！");
    }

    @ApiOperation("疫情表更新")
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public Result<String> update(@RequestBody HealthUpdateReq req){
        if(!healthService.update(req)) {
            return Result.error("更新失败！");
        }
        return Result.success("更新成功！");
    }
    @ApiOperation("学生开始填报时使用该接口获得今日是否已传决定是新增还是修改")
    @RequestMapping(value = "select",method = RequestMethod.POST)
    public Health select(String username){
        return healthService.select(username);
    }

    @ApiOperation("当日已填报人数")
    @RequestMapping(value = "/todayDeclared",method = RequestMethod.POST)
    public int countTodayDeclared(String username){
        return healthService.countTodayDeclared(username);
    }

    @ApiOperation("当日异常人数")
    @RequestMapping(value = "/todayException",method = RequestMethod.POST)
    public int countTodayException(String username){
        return healthService.countTodayException(username);
    }

    @ApiOperation("昨日异常人数")
    @RequestMapping(value = "/YesterdayException",method = RequestMethod.POST)
    public int countYesterdayException(String username){
        return healthService.countYesterdayException(username);
    }
}
